<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" v-if="getoperatorfunc(this).userType != 1">
      <el-form-item label="运营商" prop="operatorUserId" >
        <el-select v-model="queryParams.operatorUserId" placeholder="运营商" filterable clearable style="width: 200px">
          <el-option
            v-for="dict in operatorList"
            :key="dict.id"
            :label="dict.label"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="评价人名称" align="center" prop="userNickname"/>
      <el-table-column label="评价人头像" align="center" prop="userAvatar" >
        <template slot-scope="{row}">
          <el-image v-if="row.userAvatar"
            style="width: 100px; height: 100px"
            :src="row.userAvatar" 
            :preview-src-list="[row.userAvatar]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="订单id" align="center" prop="orderId"/>
      <el-table-column label="评分星级" align="center" prop="scores" >
        <template slot-scope="{row}">
          <el-rate v-model="row.scores" disabled show-score
            text-color="#ff9900" score-template="{value}">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column label="描述星级" align="center" prop="descriptionScores" >
        <template slot-scope="{row}">
          <el-rate v-model="row.descriptionScores" disabled show-score
            text-color="#ff9900" score-template="{value}">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column label="服务星级" align="center" prop="benefitScores" >
        <template slot-scope="{row}">
          <el-rate v-model="row.benefitScores" disabled show-score
            text-color="#ff9900" score-template="{value}">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column label="是否匿名" align="center" prop="anonymous">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.comm_yesno_status" :value="row.anonymous"/>
        </template>
      </el-table-column>
      <el-table-column label="是否可见" align="center" prop="visible" >
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.comm_yesno_status" :value="row.visible"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px" fixed="right">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(row)"
            v-hasPermi="['trade:serverOrder:query']"
          >查看详情</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(row)"
            v-hasPermi="['trade:serverOrder:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row class="diy-text-sm diy-leading-10" :gutter="10" v-if="title == '查看详情'">
          <el-col :span="item.span || 12" v-for="(item,index) in formDetail" :key="index">
            <div class="flex_hcneter">
              <svg-icon icon-class="dot" class-name='diy-text-primary diy-mr-1'/>
              <div v-if="item.zidian && item.isCustom" class="flex_hcneter">
                {{item.label}}：<dict-tag :options="dict.type[item.zidian]" :value="form[item.prop]"/>
              </div>
              <div v-else-if="item.type == 'textarea' && item.isCustom">
                {{item.label}}：
                <div v-html="form[item.prop]"></div>
              </div>
              <div v-else-if="item.type == 'image' && item.isCustom" class="flex_hcneter" style="margin-bottom:10px;">
                {{item.label}}：
                <el-image v-if="form[item.prop]"
                  style="width: 100px; height: 100px;"
                  :src="form[item.prop]"
                  :preview-src-list="[form[item.prop]]">
                </el-image>
              </div>
              <div v-else-if="item.prop == 'imageList' && item.isCustom">
                <h2>{{item.label}}</h2>
                <el-image  v-for="(item1,index1) in form[item.prop]" :key="index1"
                  style="width: 100px; height: 100px;margin-right:10px;margin-bottom:15px;"
                  :src="item1"
                  :preview-src-list="[item1]">
                </el-image>
              </div>
              <div v-else>{{item.label}}：{{ form[item.prop] }}{{ item.danwei || '' }}</div>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listServerOrderComment, getServerOrderComment,delServerOrderComment, } from "@/api/commodity/serviceOrderReview";
import { listAllOperator } from "@/api/operator/operatorList";
export default {
  name: "ServiceOrderReview",
  dicts: ['comm_yesno_status',],
  components: { },
  data() {
    return {
      formDetail:[//表单
        {label:'评价人名称',prop:'userNickname',},{label:'评价人头像',prop:'userAvatar',type:'image',span:24,},
        {label:'SPU 名称',prop:'spuName',},
        {label:'sku图片',prop:'skuPicUrl',type:'image',span:24,},
        {label:'属性数组',prop:'skuProperties',span:24,},
        {label:'评分星级',prop:'scores',type:'rate',},{label:'描述星级',prop:'descriptionScores',type:'rate',},{label:'服务星级',prop:'benefitScores',type:'rate',},
        {label:'评论图片',prop:'picUrls',type:'image',span:24,},
        {label:'评论内容',prop:'textarea',type:'rate',span:24,},
        {label:'是否匿名',prop:'anonymous',zidian:'comm_yesno_status',isCustom:true,},
        {label:'是否可见',prop:'visible',zidian:'comm_yesno_status',isCustom:true,},
      ],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,payStatus: undefined,operatorUserId: undefined,
        orderCode: undefined,orderStatus: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      operatorList:[],//运营商数据
    };
  },
  created() {
    this.listAllOperator()
    this.getList();
  },
  methods: {
    async listAllOperator(){//获取运营商
      let res =await listAllOperator()
      let data = res.data || []
      this.operatorList = data
    },
    /** 查列表 */
    getList() {
      this.loading = true;
      listServerOrderComment(this.queryParams).then(response => {
        let rows = response.rows || [];
        this.list = rows.map(item=>{
          return {
            ...item,
            ...this.getpricezh(item),
          }
        })
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      const id = row.id
      getServerOrderComment(id).then(response => {
        let data =  response.data || {};
        this.form = {
          ...data,
          ...this.getpricezh(data),
        }
        this.open = true;
        this.title = "查看详情";
      });
    },
    getpricezh(item){//字段转换
      let picUrls = item.picUrls || ''
      return {
        picUrls:picUrls ? picUrls.split(',') : [],
        content:this.$changeLine(item.content || ''),
      }
    },
    handleDelete(row) {//删除
      const del_ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该数据项？').then(function() {
        return delServerOrderComment(del_ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>